/**
 * @name path
 * @author Sowmya Balasubramanian, Aaron Hong, David Robertson
 */

/*
 * This is basically only path now... it still needs to be overhauled because
 * it calls GPolyline stuff in here.
 */

function PathParams() {
    this.pathsData = undefined;
    this.pathToRemove = undefined;
    this.pathToAdd = undefined;
    this.pathOnMap = undefined;
    this.pathName = undefined;
    this.pathNameCoord = undefined;
}

function getPaths() {
    console.log("getPaths called");
    GDownloadUrl(servletUrl + "servlet/?action=getPaths", function(data) {
        if (checkError(data)) {
            return;
        }
        if (typeof(JSON) === 'object' &&
            typeof(JSON.parse) === 'function') {
            wm.path.pathsData = JSON.parse(data); // native parsing available
        } else {
            wm.path.pathsData = eval("(" + data + ")");
        }
        //console.log(wm.path.pathsData);
        GEvent.trigger(wm.weathermap.eventDummy, "pathsChanged");
    });
}


function makePath() {
    console.log("makePath.start");
    if (wm.weathermap.pathChoice == "none" || wm.weathermap.pathChoice == "undef") {
        return;
    }

    //console.log(wm.path.pathsData);
    var tmpPath;
    var circuit = wm.path.pathsData[wm.weathermap.pathChoice]["hops"]["lod_" + wm.weathermap.lod];
    var numberOfHops = circuit.length;
    var index = 1;
    var type = "SDN"; //I don't think this really matters
    var pathCurve = new Array(numberOfHops);
    var nodeLat = new Array(numberOfHops);
    var nodeLong = new Array(numberOfHops); 
    console.log("Num of hops=",numberOfHops);
    for (var i = 0; i < numberOfHops; i++) {
        console.log("i: " + i);
        var node = wm.topology.topologyData[type][wm.weathermap.lod]["nodes"][circuit[i]];
        nodeLat[i] = node.latitude;
        nodeLong[i] = node.longitude;
        if (numberOfHops == 1) {
            nodeLat=new Array(numberOfHops+3);
            nodeLong=new Array(numberOfHops+3);
            nodeLat[0] = node.latitude;
            nodeLong[0] = node.longitude;
            nodeLat[1] = node.latitude-1;
            nodeLong[1]=node.longitude+1;
            nodeLat[2] = node.latitude-1;
            nodeLong[2]=node.longitude-1;
            nodeLat[3] = node.latitude;
            nodeLong[3] = node.longitude;
        }
    }
    var pathname=wm.path.pathsData[wm.weathermap.pathChoice]["description"];
    createPathDS(nodeLat,nodeLong,numberOfHops,
                wm.path.pathsData[wm.weathermap.pathChoice].bandwidth,pathname);
}
